/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.vijos;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/4/22
 */
//教主的集合序列
public class P9_1_1472 {

    public static int test(int n, int k) {
        List<Integer> arr = new ArrayList<>();
        int count = 0;
        for (int i = 1; i <= n; i++) {
            arr.add(i);
            System.out.println(i);
            count++;
        }
        if (k <= count) {
            return arr.get(k - 1);
        }
        while (true) {
            List<Integer> temp = new ArrayList<>();
            for (int i = 0; i < arr.size() - 1; i++) {
                for (int j = i + 1; j < arr.size(); j++) {
                    int value = arr.get(i) + arr.get(j);
                    System.out.println(arr.get(i) + " + " + arr.get(j) + " = " + value);
                    count++;
                    if (count == k) {
                        return value;
                    }
                    temp.add(arr.get(i) + arr.get(j));
                }
            }
            arr = temp;
        }
    }

    public static void main(String[] args) {
        System.out.println(test(3, 10));
    }
}
